const initialState = { searchParams: {} };
const searchReducer = (state = initialState, action) => {
  switch (action.type) {
    case "searchParams":
      if (action.search) {
        const searchArr = decodeURIComponent(action.search)
          .replace("?", "")
          .split("&");
        if (searchArr.length) {
          searchArr.map((item) => {
            item = item.split("=");
            state.searchParams[item[0]] = item[1];
          });
        }
      } else {
        state.searchParams = {};
      }
      break;
    default:
      break;
  }
  return state;
};
export default searchReducer;
